//---------------------------------------------------------------------------

#ifndef ShipmentBridgeH
#define ShipmentBridgeH

#include <dbtables.hpp>
#include "StringUtilities.h"
#include "ProviderBridge.h"

class TShipment : public TObject
{
   public:
      int number;
      TDateTime shipmentDate;
      Currency amount;
      TProvider* provider;

      TShipment();
      TShipment( TShipment* other);
      virtual __fastcall ~TShipment();
      
      bool IsEqual( TShipment* other);
      AnsiString GetKey();
};

class TShipmentDetails : public TObject
{
   public:
      __int64 id;
      __int64 shipmentNo;
      AnsiString firm;
      AnsiString model;
      int amount;
};

class TShipmentBridge
{
   public:
      TShipmentBridge( TDatabase * database);
      ~TShipmentBridge();

      bool IsExist( int number, TDateTime shipmentDate);
      void Get( int number, TDateTime shipmentDate, TShipment* shipment);
      void Add( TShipment* shipment);
      void Update( TShipment* oldShipment, TShipment* newShipment);
      void Delete( int number, TDateTime shipmentDate);
      void GetShipments( TStrings * shipments);

      void GetDetails(__int64 shipmentNo, TStrings * details);
      void AddDetails(TShipmentDetails * sd);
      void DeleteDetails(__int64 id);

      void UpdateDetails(__int64 shipmentNo, TStrings * details);

   private:
      TQuery * qryExists;
      TQuery * qryGet;
      TQuery * qryAdd;
      TQuery * qryUpdate;
      TQuery * qryDelete;
      TQuery * qryGetShipments;
      TQuery * qryGetDetails;
      TQuery * qryAddDetails;
      TQuery * qryDeleteDetails;
      TQuery * qrySetDetails;

      void BuildExistsQuery();
      void BuildGetQuery();
      void BuildAddQuery();
      void BuildUpdateQuery();
      void BuildDeleteQuery();
      void BuildGetShipmentsQuery();
};

#endif
